# 获取本地数据存储点的包列表
# 输入：源地址一行
# 输出：包列表
import os

from globally import LocalDataRootPath


class LocalPackList:
    def __init__(self, url):
        if url.endswith("/"):
            self.url = url + 'Packages'
        else:
            self.url = url + '/Packages'

    @property
    def packlist(self):
        packs = []
        for root, dirname, filenames in os.walk(self.__datapath):
            for mumber in filenames:
                if mumber.endswith(".rpm"):
                    packs.append(mumber)
        return packs

    # 通过url获取对应源地址存储于本地的具体路径
    @property
    def __datapath(self):
        dirlist = self.url.split('/')[3:]
        dir = LocalDataRootPath + '/'.join(dirlist)
        if not os.path.exists(dir):
            os.makedirs(dir)
        return dir




